package com.ejoysoft.wlanyz.business;

import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Vector;

import com.ejoysoft.common.DbConnect;
import com.ejoysoft.common.Format;
import com.ejoysoft.common.Globa;

public class Latlng {
	private Globa globa;
    private DbConnect db;


    public Latlng() {
    }

    public Latlng(Globa globa) {
        this.globa = globa;
        db = globa.db;
    }

    public Latlng(Globa globa, boolean b) {
        this.globa = globa;
        db = globa.db;
        if (b) globa.setDynamicProperty(this);
    }

    String strTableName = "ac_lat_lng";
//返回单条记录
    public Latlng show(String where) {
        try {
            String strSql = "select * from  " + strTableName + "  ".concat(where);
            ResultSet rs = db.executeQuery(strSql);
            if (rs != null && rs.next())
                return load(rs, true);
            else
                return null;
        } catch (Exception ee) {
            return null;
        }
    }

    public boolean update(String strId) {
        try {
            String strSql = "UPDATE  " + strTableName + "  SET  checkedLocation = ?, distance = ?, strCreator = ?, dtCreateTime = to_date(?,'yyyy-MM-dd hh24:mi:ss') WHERE strId=? ";
            db.prepareStatement(strSql);
            db.setString(1, checkedLocation);
            db.setString(2, String.valueOf(distance));
            db.setString(3, globa.loginName);
            db.setString(4, Format.getDateTime()); 
            db.setString(5, strId);
            db.executeUpdate();
             System.out.println("修改成功！！！");
            Globa.logger0("修改热点信息", globa.loginName, globa.loginIp, strSql, "热点信息", globa.userSession.getStrDepart());
            return true;
        } catch (Exception e) {
            System.out.println("修改用户信息时出错：" + e);
            return false;
        }
    }

    //记录集转化为对象
    public Latlng load(ResultSet rs, boolean isView) {
        Latlng theBean = new Latlng();
        try {
            Ac objAc = new Ac(globa);
        	Ac objAc2 = objAc.show(" where strId='"+rs.getString("acName")+"'");
        	String acName = objAc2==null?"":objAc2.getClassTwoAC();
            theBean.setStrId(rs.getString("strId"));
            theBean.setAcName(acName);
            theBean.setAcLocation(rs.getString("acLocation"));
            theBean.setOriginalLocation(rs.getString("originalLocation"));
            theBean.setCheckedLocation(rs.getString("checkedLocation")); 
            theBean.setDistance(rs.getDouble("distance"));
            theBean.setStrCreator(rs.getString("strCreator"));
            theBean.setdCreatDate(rs.getString("dtCreateTime"));
            theBean.setStrAcId(rs.getString("acName"));
            theBean.setPhoneLocation(rs.getString("phoneLocation"));
        } catch (Exception e) {
            e.printStackTrace();        
        }
        return theBean;
    }

  //查询符合条件的记录总数
    public int getCount(String where) {
        int count = 0;
        try {
            String sql = "SELECT count(strId) FROM " + strTableName + "  ";
            if (where.length() > 0) {
                where = where.toLowerCase();
                if (where.indexOf("order") > 0)
                    where = where.substring(0, where.lastIndexOf("order"));
                sql = String.valueOf(sql) + String.valueOf(where);
            }
            ResultSet rs = db.executeQuery(sql);
            if (rs != null && rs.next())
                count = rs.getInt(1);
            rs.close();
            return count;
        } catch (Exception ee) {
            ee.printStackTrace();
            System.out.println(ee);           
            return count;
        }
    }




  //列表记录集
    public Vector<Latlng> list(String where, int startRow, int rowCount) {
        Vector<Latlng> beans = new Vector<Latlng>();
        try {
            String sql = "SELECT *  FROM  " + strTableName + " ";
            if (where.length() > 0)
                sql = String.valueOf(sql) + String.valueOf(where);
            Statement s = db.getConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
            if (startRow != 0 && rowCount != 0)
                s.setMaxRows((startRow + rowCount) - 1);
            ResultSet rs = s.executeQuery(sql);
            if (rs != null && rs.next()) {
                if (startRow != 0 && rowCount != 0)
                    rs.absolute(startRow);
                do {
                    Latlng theBean = new Latlng();
                    theBean = load(rs, false);
                    beans.addElement(theBean);
                } while (rs.next());
            }
            rs.close();
            s.close();
        } catch (Exception ee) {
            ee.printStackTrace();
        }
        return beans;
    }


    private String strId;//	id号
    private String acName;//		热点名称
    private String acLocation;//			热点地址
    private String originalLocation;//		热点的系统中经纬度大小
    private String checkedLocation;//		热点被解析后的经纬度大小
    private double distance;//		系统中经纬度和解析后经纬度之间的实际距离大小（单位米）
    private String strCreator;//			创建人
    private String dCreatDate;//		创建时间
    private String strAcId;
    private String phoneLocation;//         热点在手机终端的定位的经纬度大小


    public String getStrId() {
        return strId;
    }

    public void setStrId(String strId) {
        this.strId = strId;
    }

    public String getAcName() {
        return acName;
    }

    public void setAcName(String acName) {
        this.acName = acName;
    }
    
    public String getAcLocation() {
		return acLocation;
	}
    
    public void setAcLocation(String acLocation){
    	 this.acLocation = acLocation;
    }
    
    public String getOriginalLocation() {
		return originalLocation;
	}
    
    public void setOriginalLocation(String originalLocation){
    	this.originalLocation = originalLocation;
    }
    
    public String getCheckedLocation() {
		return checkedLocation;
	}
    
    public void setCheckedLocation(String checkedLocation) {
		this.checkedLocation = checkedLocation;
	}

    public double getDistance() {
		return distance;
	}
    
    public void setDistance(double distance) {
		this.distance = distance;
	}
 
    public String getStrCreator() {
        return strCreator;
    }

    public void setStrCreator(String strCreator) {
        this.strCreator = strCreator;
    }

    public String getdCreatDate() {
        return dCreatDate;
    }

    public void setdCreatDate(String dCreatDate) {
        this.dCreatDate = dCreatDate;
    }

	public String getStrAcId() {
		return strAcId;
	}

	public void setStrAcId(String strAcId) {
		this.strAcId = strAcId;
	}
	public String getPhoneLocation() {
		return phoneLocation;
	}
    
    public void setPhoneLocation(String phoneLocation){
    	this.phoneLocation = phoneLocation;
    }
    
}
